import { inject } from '@loopback/context';
import {
  AuthenticationBindings,
  UserProfile,
  authenticate,
} from '@loopback/authentication';

import { post, requestBody } from '@loopback/rest';

export class LoginController {
  constructor(
    @inject(AuthenticationBindings.CURRENT_USER)
    private user: UserProfile,
  ) { }

  // 登录认证
  @authenticate('BasicStrategy')
  @post('/login')
  login(@requestBody() loginInfo: LoginInfo): string {

    console.log('loginInfo: ' + JSON.stringify(loginInfo));

    return loginInfo.password!!;
  }
}

export interface LoginInfo {
  username?: string;
  password?: string;
  email?: string;
}
